/*
                    Listitem Class Implementation
*/
#include "Listitem.h"

Listitem::Listitem()
{
    TTFfont = NULL;
    Image = NULL;

    Position = Point(0,0);

    ForeColour.r = 0;
    ForeColour.g = 0;
    ForeColour.b = 0;

    bEnabled = true;
}

Listitem::~Listitem()
{
    if (TTFfont != NULL)
    {
        TTF_CloseFont(TTFfont);
        TTFfont = NULL;
    }

    if (Image != NULL) { SDL_FreeSurface(Image); Image = NULL; }
}

int Listitem::Initialise(string strFilepath, int iNewSize, string strNewText, SDL_Color NewColor)
{
    iSize = iNewSize;

    ForeColour = NewColor;

    TTFfont = TTF_OpenFont(strFilepath.c_str(), iSize);

    if (TTFfont == NULL)
    {
        printf("Font Init Error: %s\n", TTF_GetError());
        return -1;
    }

    strText = strNewText;

    UpdateText();
}

int Listitem::HandleMouseDown(int iMouseX, int iMouseY)
{
    double xpos = Position.x;
    double ypos = Position.y;

    int iWidth = Image->w;
    int iHeight = Image->h;

    if((iMouseX > xpos) && (iMouseX < xpos + iWidth) && (iMouseY > ypos) && (iMouseY < ypos + iHeight))
    {
        return 1;
    }

    return 0;
}
